package cloudspace.ui.impl;

import org.apache.log4j.Logger;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import cloudspace.controlpanel.filemanager.FileManagerController;


public class PasswordDialog extends Window
{
    // ~ Constructors ..........................................................

    // ----------------------------------------------------------
    public PasswordDialog()
    {
        result = null;
    }


    // ~ Methods ...............................................................

    // ----------------------------------------------------------
    public void onOK()
    {
        Textbox textbox1 = (Textbox)getFellow( "promptValue1" );
        Textbox textbox2 = (Textbox)getFellow( "promptValue2" );
        String pass1 = textbox1.getText();
        String pass2 = textbox2.getText();
        if ( pass1.equals( pass2 ) )
        {
            result = pass1;
            detach();
        }
        else
        {
            try
            {
                Messagebox.show( "Your passwords did not match!",
                    "Error",
                    org.zkoss.zhtml.Messagebox.OK,
                    org.zkoss.zhtml.Messagebox.ERROR );
            }
            catch ( InterruptedException e )
            {
                log.error( "Passwords did not match for reset and error not shown",
                    e );
            }
        }
    }


    // ----------------------------------------------------------
    public String getNewPassword()
    {
        return result;
    }

    // ~ Static/instance variables .............................................

    private static final long serialVersionUID = 6081953395500563691L;

    private String result;

    private static Logger log = Logger.getLogger( FileManagerController.class );
}
